import Vue from 'vue'
import VueRouter from 'vue-router'

// Vue.use(VueRouter)

// 首页用重定向的方式来进行适配的方案：
// const redirectPath = /Android |webos | iphone iPod BlackBerry liPad/i.test(navigator.userAgent) ? '/moveIndex' : '/pcIndex';


const routes = [
  {
    path: '/',
    name: 'pcIndex',
    component: () => import('../views/Index.vue')
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('../views/Home.vue')
  },
  {
    path: '/blog/:id',
    name: 'Blog',
    props: true,
    component: () => import('../components/Blog.vue')
  },
  {
    path: '/blogType',
    name: 'BlogType',
    component: () => import('../views/BlogType.vue')
  },
  {
    path: '/blogTag',
    name: 'BlogTag',
    component: () => import('../views/BlogTag.vue')
  },
  {
    path: '/blogSearch',
    name: 'BlogSearch',
    // props: true,
    component: () => import('../views/BlogSearch.vue')
  },
  {
    path: '/message',
    name: 'Message',
    component: () => import('../views/Message.vue')
  },
  {
    path: '/blogLinks',
    name: 'BlogLinks',
    component: () => import('../views/BlogLinks.vue')
  },
]

const router = new VueRouter({
  // 去掉路由中的#号
  // mode:'history', //去掉#号// mode: 'history',
  mode: 'hash',
  routes,
  scrollBehavior(to, from, savedPosition){
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})

// router.beforeEach((to, from, next) => {
//   if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
//   // if(true){
//   //   window.location.href = 'http://localhost:8081/public/move.html'
//   //   window.location.href = '/move.html/'
//     window.location.href = '/frontmove/'
//     return
//   }
//   next()
// })

export default router
